//https://leetcode-cn.com/problems/simple-bank-system/
package main

type Bank struct {
	Balance []int64
	Number  int
}

func Constructor(balance []int64) Bank {
	b := &Bank{balance, len(balance)}
	return *b
}

func (this *Bank) Transfer(account1 int, account2 int, money int64) bool {
	if account1 > this.Number || account2 > this.Number || this.Balance[account1-1] < money {
		return false
	}
	this.Balance[account1-1] -= money
	this.Balance[account2-1] += money
	return true
}

func (this *Bank) Deposit(account int, money int64) bool {
	if this.Number < account {
		return false
	}
	this.Balance[account-1] += money
	return true
}

func (this *Bank) Withdraw(account int, money int64) bool {
	if this.Number < account || this.Balance[account-1] < money {
		return false
	}
	this.Balance[account-1] -= money
	return true
}

func main() {
	b := Constructor([]int64{10, 100, 20, 50, 30})
	println(b.Withdraw(3, 10))
	println(b.Transfer(5, 1, 20))
	println(b.Deposit(5, 20))
	println(b.Transfer(3, 4, 15))
	println(b.Withdraw(10, 50))
}
